﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

public partial class check_in : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Form["TRIP"] == null)
            {
                Response.Write("Illegal page call!");
                return;
            }
            string key;
            string[] strArray;
            key = Request.Form["TRIP"];
            strArray = key.Split('|');
            int pax_sn,trip_sn;
            long order;
            try
            {
                order = Convert.ToInt64(strArray[0]);
                pax_sn = Convert.ToInt16(strArray[1]);
                trip_sn = Convert.ToInt16(strArray[2]);
            }
            catch (Exception ex)
            {
                lblError.Text = "非法票号！";
                return;
            }
            hidOrderNo.Value = order.ToString();
            hidPaxSn.Value = pax_sn.ToString();
            hidTripSn.Value = trip_sn.ToString();
            btnRefreshSeatMap_Click(sender, e);
        }
    }
    protected void btnRefreshSeatMap_Click(object sender, EventArgs e)
    {
        int ret_code = 0;
        ret_code=select_seat_map1.RetreiveSeatMap(Convert.ToInt64(hidOrderNo.Value), Convert.ToInt16(hidPaxSn.Value), Convert.ToInt16(hidTripSn.Value), Application["UID"].ToString(), true);
        lblError.Text = ret_code.ToString();
        return;

    }
    protected void btnCheckIn_Click(object sender, EventArgs e)
    {
        if (Request.Form["SEAT"] == null)
        {
            lblError.Text = "请选择座位";
            return;
        }
        string key;
        string[] strArray;
        key = Request.Form["SEAT"].ToString();
        strArray = key.Split('|');
        int row;
        string col;
        try
        {
            row = Convert.ToInt16(strArray[0]);
            col=strArray[1];
        }
        catch (Exception ex)
        {
            lblError.Text = "非法票号！";
            return;
        }
        CRSI.Ticket inst = new CRSI.Ticket();
        int ret_code = 0;
        string ret_msg;
        //string pwd_sha1 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Application["PWD"].ToString(), "SHA1");
        string sign = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(hidOrderNo.Value + "|" + hidPaxSn.Value + "|" + hidTripSn.Value + "|" + row.ToString() + "|" + col + "|" + Application["HASH_PWD"].ToString(), "MD5");
        ret_code = inst.TripCheckIn(Convert.ToInt64(hidOrderNo.Value), Convert.ToInt16(hidPaxSn.Value), Convert.ToInt16(hidTripSn.Value),row,col, Application["UID"].ToString(), sign, out ret_msg);
        if (ret_code < 0)
        {
            lblError.Text = ret_msg;
            return;
        }
        switch (ret_code)
        {
            case 0:
                lblError.Text = "已办妥乘机手续，请返回并重新打印行程单。如需托运行李，请到机场柜台办理。";
                break;
            case 1:
                lblError.Text = "机票未找到。";
                break;
            case 3:
                lblError.Text = "航班找到或未开放值机。";
                break;
            case 4:
                lblError.Text = "机票已过期。";
                break;
            case 10:
                lblError.Text = "派位失败。";
                break;
            case 11:
                lblError.Text = "更新机票状态失败。";
                break;
            case 50:
                lblError.Text = "没有权限。";
                break;
            case 91:
                lblError.Text = "登录错";
                break;
            default:
                lblError.Text = "未知错误：" + ret_code.ToString();
                break;
        }
    }
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        if (Request.Form["SEAT"] == null)
        {
            lblError.Text = "请选择座位";
            return;
        }
        string key;
        string[] strArray;
        key = Request.Form["SEAT"].ToString();
        strArray = key.Split('|');
        int row;
        string col;
        try
        {
            row = Convert.ToInt16(strArray[0]);
            col = strArray[1];
        }
        catch (Exception ex)
        {
            lblError.Text = "非法票号！";
            return;
        }
        CRSI.Ticket inst = new CRSI.Ticket();
        int ret_code = 0;
        string ret_msg;
        //string pwd_sha1 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Application["PWD"].ToString(), "SHA1");
        string sign = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(hidOrderNo.Value + "|" + hidPaxSn.Value + "|" + hidTripSn.Value + "|" + row.ToString() + "|" + col + "|" + Application["HASH_PWD"].ToString(), "MD5");
        ret_code = inst.TripSelectSeat(Convert.ToInt64(hidOrderNo.Value), Convert.ToInt16(hidPaxSn.Value), Convert.ToInt16(hidTripSn.Value), row, col, Application["UID"].ToString(), sign, out ret_msg);
        if (ret_code < 0)
        {
            lblError.Text = ret_msg;
            return;
        }
        switch (ret_code)
        {
            case 0:
                lblError.Text = "已成功选位，待开放值机后可值机。请返回并重新打印行程单。";
                break;
            case -1:
                lblError.Text = "错误的用户ID。";
                break;
            case 1:
                lblError.Text = "机票未找到。";
                break;
            case 3:
                lblError.Text = "航班找到或不许选位。";
                break;
            case 10:
                lblError.Text = "选位失败。";
                break;
            case 11:
                lblError.Text = "更新机票状态失败。";
                break;
            case 12:
                lblError.Text = "释放原座位失败!";
                break;
            case 50:
                lblError.Text = "没有权限。";
                break;
            case 91:
                lblError.Text = "登录错";
                break;
            default:
                lblError.Text = "未知错误：" + ret_code.ToString();
                break;
        }
    }
}
